//
//  XMLParser.m
//  OR_1
//
//  Created by Luboš Kulič on 7/30/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "XMLParser.h"
#import "ORShortcutsParser.h"
#import "Stack.h"





@interface XMLParser (XMLDelegateMethods)

-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;

-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;

-(void) parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock;

-(void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

-(void)parser:(NSXMLParser *)parser foundIgnorableWhitespace:(NSString *)whitespaceString;

@end


//@interface XMLParser (XMLParserPrivateMethods)
//
//-(void)emtyAuxData;
//
//@end




@implementation XMLParser


-(id) init {
	if(!(self = [super init])) {
		return 0;
	}	
	
	previousWorker = self;
	return self;	
}

-(void) dealloc {
	
	[super dealloc];
		
}


-(DataItem *)parse:(NSData *)data {
	NSLog(@"Starting data parsing");
	
	NSXMLParser *parser = [[[NSXMLParser alloc]initWithData:data] autorelease];
	
	[self initAuxData];
	[parser setDelegate:self];
	
	[parser parse];
	
	NSLog(@"ORStatement: %@", ORStatement);
	return [ORStatement autorelease];
		
}



-(void) parserWillStartSubelement:(NSString *)elementName withWorker:(XMLParserWorker *)newWorker {
	NSLog(@"Parser start Element: %@", elementName);

	[super parserWillStartSubelement:elementName withWorker:newWorker];
	
	if ([@"D:Vypis_OR" isEqualToString:elementName]) {
		NSLog(@"Stroing Vypis OR");
		self->ORStatement = [(DataItem*) newWorker retain];
	}
}



@end
